#! /usr/bin/perl -w

###################################################################################################
#
#    AUTHOR:  Johan Dahlberg
#    VERSION: Version 1.0 (19 April 2011)
#    PURPOSE: Clear the data form the genotype table.
#    INPUT: void
#    OUTPUT FILES: void
#
###################################################################################################

use strict;
use DBI;

my $filename = $ARGV[0];

# ---------------------------------
# This part reads the db-settnings.
# ---------------------------------

my $db_config_path = "../Perl/db_settings.txt";

#### Open input file
open DB_FILE, "<$db_config_path"
	or die "Something's wrong with the db config file!\n";

my $db_line = <DB_FILE>;		# holds the current line from the input file
my @db_conf_arr = split(/\s+/, $db_line);
my $username = shift @db_conf_arr;
my $password = shift @db_conf_arr;
my $database = shift @db_conf_arr;

close DB_FILE
        or die "Problem closing db-config file.\n";

# ----------------------------------------
# End reading db-settings.
# ----------------------------------------


### Create a connection to the database
my $dbh = DBI->connect(
    		"DBI:mysql:$database:localhost:3306",
    		$username,
    		$password
)or die "$DBI::errstr\n";

### Clear the genotype table!

my $clear_gene_handle = $dbh->prepare_cached('DELETE FROM genotype')
	or die "Couldn't remove data from table genotype.";

$clear_gene_handle->execute()
	or die "Couldn't execute delete on genotypes.";

$dbh->disconnect();
